package com.demo.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import com.demo.helper.BatteryHelper;
import com.module.commonui.R;

public class DeviceDataView extends LinearLayout {
    private ImageView mImageView;
    private TextView mTvRecordVideo;
    private TextView mTvPlayerBitrate;
    private TextView mTvPlayerSignal;
    private TextView mTvFrameRate;

    private int mMode = 0;
    private int mBattery = 0;
    private int mRecordType = 0;
    private int mBatteryLow = 0;

    public void setRecordType(int recordType) {
        this.mRecordType = recordType;
        showUIInfo();
    }

    public DeviceDataView(Context context) {
        super(context);
        initContentView(context);
    }

    public DeviceDataView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public DeviceDataView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initContentView(context);
    }


    public TextView getTvRecordVideo() {
        return mTvRecordVideo;
    }

    public void setTvRecordVideo(TextView tvRecordVideo) {
        this.mTvRecordVideo = tvRecordVideo;
    }

    public TextView getTvPlayerBitrate() {
        return mTvPlayerBitrate;
    }

    public void setTvPlayerBitrate(TextView tvPlayerBitrate) {
        this.mTvPlayerBitrate = tvPlayerBitrate;
    }

    public TextView getTvPlayerSignal() {
        return mTvPlayerSignal;
    }

    public void setTvPlayerSignal(TextView tvPlayerSignal) {
        this.mTvPlayerSignal = tvPlayerSignal;
    }

    public TextView getTvFrameRate() {
        return mTvFrameRate;
    }

    public void setTvFrameRate(TextView tvFrameRate) {
        this.mTvFrameRate = tvFrameRate;
    }

    private void initContentView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.device_data_info, this, true);

        mImageView = view.findViewById(R.id.iv_battery);
        mTvRecordVideo = view.findViewById(R.id.tv_record_video);
        mTvPlayerBitrate = view.findViewById(R.id.tv_player_bitrate);
        mTvPlayerSignal = view.findViewById(R.id.tv_player_signal);
        mTvFrameRate = view.findViewById(R.id.tv_frame_rate);
    }


    public void setImageResource(@DrawableRes int resId){
        mImageView.setImageResource(resId);
    }

    public void  updateBatteryStatus(int battery, int mode, int batteryLow){
        mMode = mode;
        mBattery = battery;
        mBatteryLow = batteryLow;
        showUIInfo();
    }

    private void showUIInfo() {
        BatteryHelper.setBattery(mImageView, mMode, mBattery, false);
    }
}
